package com.campusevaluation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campusevaluation.common.exception.BasePage;
import com.campusevaluation.common.exception.Result;
import com.campusevaluation.domain.dto.DepartmentDTO;
import com.campusevaluation.domain.po.Department;
import com.campusevaluation.domain.vo.DepartmentVO;
import com.campusevaluation.service.IDepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("/department")
@Tag(name = "部门管理模块")
public class DepartmentController {
    @Resource
    private IDepartmentService departmentService;

    @Operation(summary = "创建部门")
    @PostMapping("/add")
    public Result<String> createDepartment(@RequestBody DepartmentDTO departmentDTO) {
        return departmentService.createDepartment(departmentDTO);
    }

    @Operation(summary = "删除部门")
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteDepartment(@PathVariable("id") Long id) {
        return departmentService.deleteDepartment(id);
    }

    @Operation(summary = "分页查询部门")
    @PostMapping("/page_departments")
    public Result<Page<Department>> getDepartmentsByPage(@RequestBody BasePage basePage) {
        return departmentService.getDepartmentsByPage(basePage);
    }

    @Operation(summary = "根据ID获取部门")
    @GetMapping("/get/{id}")
    public Result<DepartmentVO> getDepartmentById(@PathVariable("id") Long id) {
        return departmentService.getDepartmentById(id);
    }

    @Operation(summary = "修改部门")
    @PutMapping("/update")
    public Result<String> updateDepartment(@RequestBody DepartmentDTO departmentDTO) {
        return departmentService.updateDepartment(departmentDTO);
    }

    @Operation(summary = "批量删除部门")
    @DeleteMapping("/delete_department_batch")
    public Result<String> deleteDepartmentBatch(@RequestBody List<Long> ids) {
        return departmentService.deleteBatchByIds(ids);
    }

}
